{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This builds the sphinx/readthedocs documentation. \n",
    "\n",
    "Remember to start a shell from the terminal app instead of from the pycharm project or else will\n",
    "activate the virtual environment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "refresh_static_folder = True\n",
    "\n",
    "from shutil import copyfile\n",
    "if refresh_static_folder:\n",
    "    sphinx_prefix = 'source/_static/'\n",
    "    home_prefix = '../qubiter/'\n",
    "    cg_name = 'classgraph.pdf'\n",
    "    cgo_name = 'classgraph_orphans.html'\n",
    "    ros_name = 'qubiter_rosetta_stone.pdf'\n",
    "    copyfile(home_prefix + cg_name, sphinx_prefix + cg_name)\n",
    "    copyfile(home_prefix + cgo_name, sphinx_prefix + cgo_name)\n",
    "    copyfile(home_prefix + ros_name, sphinx_prefix + ros_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating file source/qubiter.rst.\n",
      "Creating file source/qubiter.BitVector.rst.\n",
      "Creating file source/qubiter.CGateExpander.rst.\n",
      "Creating file source/qubiter.CGateSEO_writer.rst.\n",
      "Creating file source/qubiter.CktEmbedder.rst.\n",
      "Creating file source/qubiter.CodaSEO_writer.rst.\n",
      "Creating file source/qubiter.Controls.rst.\n",
      "Creating file source/qubiter.EchoingSEO_reader.rst.\n",
      "Creating file source/qubiter.FouSEO_writer.rst.\n",
      "Creating file source/qubiter.HadamardTransform.rst.\n",
      "Creating file source/qubiter.LoopFileGenerator.rst.\n",
      "Creating file source/qubiter.LoopyPlaceholderManager.rst.\n",
      "Creating file source/qubiter.OneQubitGate.rst.\n",
      "Creating file source/qubiter.PlaceholderManager.rst.\n",
      "Creating file source/qubiter.Plotter.rst.\n",
      "Creating file source/qubiter.SEO_Lista.rst.\n",
      "Creating file source/qubiter.SEO_MatrixProduct.rst.\n",
      "Creating file source/qubiter.SEO_pre_reader.rst.\n",
      "Creating file source/qubiter.SEO_reader.rst.\n",
      "Creating file source/qubiter.SEO_simulator.rst.\n",
      "Creating file source/qubiter.SEO_simulator_tf.rst.\n",
      "Creating file source/qubiter.SEO_writer.rst.\n",
      "Creating file source/qubiter.StateVec.rst.\n",
      "Creating file source/qubiter.UnitaryMat.rst.\n",
      "Creating file source/qubiter.classgraph.rst.\n",
      "Creating file source/qubiter.run_all_nb.rst.\n",
      "Creating file source/qubiter.run_all_py.rst.\n",
      "Creating file source/qubiter.utilities_gen.rst.\n",
      "Creating file source/qubiter.adv_applications.rst.\n",
      "Creating file source/qubiter.adv_applications.CostMinimizer.rst.\n",
      "Creating file source/qubiter.adv_applications.MeanHamil.rst.\n",
      "Creating file source/qubiter.adv_applications.MeanHamilMinimizer.rst.\n",
      "Creating file source/qubiter.adv_applications.MeanHamil_native.rst.\n",
      "Creating file source/qubiter.adv_applications.MeanHamil_rigetti.rst.\n",
      "Creating file source/qubiter.adv_applications.PhaseEstSEO_writer.rst.\n",
      "Creating file source/qubiter.adv_applications.StairsAllDeriv_native.rst.\n",
      "Creating file source/qubiter.adv_applications.StairsAllDeriv_rigetti.rst.\n",
      "Creating file source/qubiter.adv_applications.StairsCkt_writer.rst.\n",
      "Creating file source/qubiter.adv_applications.StairsDeriv.rst.\n",
      "Creating file source/qubiter.adv_applications.StairsDerivCkt_writer.rst.\n",
      "Creating file source/qubiter.adv_applications.StairsDerivThrCkt_writer.rst.\n",
      "Creating file source/qubiter.adv_applications.StairsDeriv_native.rst.\n",
      "Creating file source/qubiter.adv_applications.StairsDeriv_rigetti.rst.\n",
      "Creating file source/qubiter.adv_applications.setup_autograd.rst.\n",
      "Creating file source/qubiter.device_specific.rst.\n",
      "Creating file source/qubiter.device_specific.ChipCouplingsFitter.rst.\n",
      "Creating file source/qubiter.device_specific.ForbiddenCNotExpander.rst.\n",
      "Creating file source/qubiter.device_specific.QbitPlanarLattice.rst.\n",
      "Creating file source/qubiter.device_specific.Qubiter_to_AnyQasm.rst.\n",
      "Creating file source/qubiter.device_specific.Qubiter_to_GoogleCirq.rst.\n",
      "Creating file source/qubiter.device_specific.Qubiter_to_IBMqasm.rst.\n",
      "Creating file source/qubiter.device_specific.Qubiter_to_PennyLane.rst.\n",
      "Creating file source/qubiter.device_specific.Qubiter_to_RigettiPyQuil.rst.\n",
      "Creating file source/qubiter.device_specific.RigettiTools.rst.\n",
      "Creating file source/qubiter.device_specific.chip_couplings_google.rst.\n",
      "Creating file source/qubiter.device_specific.chip_couplings_ibm.rst.\n",
      "Creating file source/qubiter.device_specific.chip_couplings_rigetti.rst.\n",
      "Creating file source/qubiter.device_specific.utilities_ds.rst.\n",
      "Creating file source/qubiter.io_folder.rst.\n",
      "Creating file source/qubiter.io_folder.loop_gen_test_4_loop.rst.\n",
      "Creating file source/qubiter.io_folder.loop_gen_test_4_loop1.rst.\n",
      "Creating file source/qubiter.io_folder.qbtr2penny_test1_PennyL.rst.\n",
      "Creating file source/qubiter.io_folder.qbtr2penny_test2_PennyL.rst.\n",
      "Creating file source/qubiter.io_folder.qbtr2penny_test2_fun_defs.rst.\n",
      "Creating file source/qubiter.jupyter_notebooks.rst.\n",
      "Creating file source/qubiter.jupyter_notebooks.utilities_nb.rst.\n",
      "Creating file source/qubiter.latex_tools.rst.\n",
      "Creating file source/qubiter.latex_tools.AsciiPic_to_Latex.rst.\n",
      "Creating file source/qubiter.quantum_CSD_compiler.rst.\n",
      "Creating file source/qubiter.quantum_CSD_compiler.CS_Decomp.rst.\n",
      "Creating file source/qubiter.quantum_CSD_compiler.DiagUnitaryExpander.rst.\n",
      "Creating file source/qubiter.quantum_CSD_compiler.DiagUnitarySEO_writer.rst.\n",
      "Creating file source/qubiter.quantum_CSD_compiler.MultiplexorExpander.rst.\n",
      "Creating file source/qubiter.quantum_CSD_compiler.MultiplexorSEO_writer.rst.\n",
      "Creating file source/qubiter.quantum_CSD_compiler.Node.rst.\n",
      "Creating file source/qubiter.quantum_CSD_compiler.Tree.rst.\n",
      "Creating file source/modules.rst.\n"
     ]
    }
   ],
   "source": [
    "!sphinx-apidoc --separate -f -o source/ ../qubiter\n",
    "#!/home/rrtucci/anaconda3/bin/sphinx-apidoc --separate -f -o source/ ../qubiter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[01mRunning Sphinx v2.2.0\u001b[39;49;00m\n",
      "\u001b[01mloading pickled environment... \u001b[39;49;00mdone\n",
      "\u001b[01mbuilding [mo]: \u001b[39;49;00mall of 0 po files\n",
      "\u001b[01mbuilding [html]\u001b[39;49;00m: all source files\n",
      "\u001b[01mupdating environment: \u001b[39;49;00m0 added, 4 changed, 0 removed\n",
      "\u001b[01mreading sources... \u001b[39;49;00m[100%] \u001b[35mqubiter.run_all_py\u001b[39;49;00m                                    \n",
      "\u001b[31;01m/home/rrtucci/PycharmProjects/qubiter/sphinx_doc/source/qubiter.rst:7: WARNING: toctree contains reference to excluded document 'qubiter.io_folder'\u001b[39;49;00m\n",
      "\u001b[31;01mWARNING: autodoc: failed to import module 'classgraph' from module 'qubiter'; the following exception was raised:\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/rrtucci/anaconda3/lib/python3.7/site-packages/sphinx/ext/autodoc/importer.py\", line 32, in import_module\n",
      "    return importlib.import_module(modname)\n",
      "  File \"/home/rrtucci/anaconda3/lib/python3.7/importlib/__init__.py\", line 127, in import_module\n",
      "    return _bootstrap._gcd_import(name[level:], package, level)\n",
      "  File \"<frozen importlib._bootstrap>\", line 1006, in _gcd_import\n",
      "  File \"<frozen importlib._bootstrap>\", line 983, in _find_and_load\n",
      "  File \"<frozen importlib._bootstrap>\", line 967, in _find_and_load_unlocked\n",
      "  File \"<frozen importlib._bootstrap>\", line 677, in _load_unlocked\n",
      "  File \"<frozen importlib._bootstrap_external>\", line 728, in exec_module\n",
      "  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\n",
      "  File \"/home/rrtucci/PycharmProjects/qubiter/qubiter/classgraph.py\", line 35, in <module>\n",
      "    for fname in os.listdir(dir_name):\n",
      "FileNotFoundError: [Errno 2] No such file or directory: 'adv_applications'\n",
      "\u001b[39;49;00m\n",
      "\u001b[31;01mWARNING: autodoc: failed to import module 'run_all_nb' from module 'qubiter'; the following exception was raised:\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/rrtucci/anaconda3/lib/python3.7/site-packages/sphinx/ext/autodoc/importer.py\", line 32, in import_module\n",
      "    return importlib.import_module(modname)\n",
      "  File \"/home/rrtucci/anaconda3/lib/python3.7/importlib/__init__.py\", line 127, in import_module\n",
      "    return _bootstrap._gcd_import(name[level:], package, level)\n",
      "  File \"<frozen importlib._bootstrap>\", line 1006, in _gcd_import\n",
      "  File \"<frozen importlib._bootstrap>\", line 983, in _find_and_load\n",
      "  File \"<frozen importlib._bootstrap>\", line 967, in _find_and_load_unlocked\n",
      "  File \"<frozen importlib._bootstrap>\", line 677, in _load_unlocked\n",
      "  File \"<frozen importlib._bootstrap_external>\", line 728, in exec_module\n",
      "  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\n",
      "  File \"/home/rrtucci/PycharmProjects/qubiter/qubiter/run_all_nb.py\", line 9, in <module>\n",
      "    for fname in os.listdir(dir_name):\n",
      "FileNotFoundError: [Errno 2] No such file or directory: 'jupyter_notebooks'\n",
      "\u001b[39;49;00m\n",
      "\u001b[31;01mWARNING: autodoc: failed to import module 'run_all_py' from module 'qubiter'; the following exception was raised:\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/rrtucci/anaconda3/lib/python3.7/site-packages/sphinx/ext/autodoc/importer.py\", line 32, in import_module\n",
      "    return importlib.import_module(modname)\n",
      "  File \"/home/rrtucci/anaconda3/lib/python3.7/importlib/__init__.py\", line 127, in import_module\n",
      "    return _bootstrap._gcd_import(name[level:], package, level)\n",
      "  File \"<frozen importlib._bootstrap>\", line 1006, in _gcd_import\n",
      "  File \"<frozen importlib._bootstrap>\", line 983, in _find_and_load\n",
      "  File \"<frozen importlib._bootstrap>\", line 967, in _find_and_load_unlocked\n",
      "  File \"<frozen importlib._bootstrap>\", line 677, in _load_unlocked\n",
      "  File \"<frozen importlib._bootstrap_external>\", line 728, in exec_module\n",
      "  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\n",
      "  File \"/home/rrtucci/PycharmProjects/qubiter/qubiter/run_all_py.py\", line 22, in <module>\n",
      "    for fname in os.listdir(dir_name):\n",
      "FileNotFoundError: [Errno 2] No such file or directory: 'adv_applications'\n",
      "\u001b[39;49;00m\n",
      "\u001b[01mlooking for now-outdated files... \u001b[39;49;00mnone found\n",
      "\u001b[01mpickling environment... \u001b[39;49;00mdone\n",
      "\u001b[01mchecking consistency... \u001b[39;49;00m\u001b[31;01m/home/rrtucci/PycharmProjects/qubiter/sphinx_doc/source/modules.rst: WARNING: document isn't included in any toctree\u001b[39;49;00m\n",
      "\u001b[31;01m/home/rrtucci/PycharmProjects/qubiter/sphinx_doc/source/qubiter.OneBitGates.rst: WARNING: document isn't included in any toctree\u001b[39;49;00m\n",
      "done\n",
      "\u001b[01mpreparing documents... \u001b[39;49;00mdone\n",
      "\u001b[01mwriting output... \u001b[39;49;00m[100%] \u001b[32mrosetta\u001b[39;49;00m                                                \n",
      "\u001b[01mgenerating indices... \u001b[39;49;00m genindex py-modindexdone\n",
      "\u001b[01mhighlighting module code... \u001b[39;49;00m[100%] \u001b[34;01mqubiter.utilities_gen\u001b[39;49;00m                        9;00m\n",
      "\u001b[01mwriting additional pages... \u001b[39;49;00m search/home/rrtucci/anaconda3/lib/python3.7/site-packages/sphinx_rtd_theme/search.html:20: RemovedInSphinx30Warning: To modify script_files in the theme is deprecated. Please insert a <script> tag directly in your theme instead.\n",
      "  {{ super() }}\n",
      "done\n",
      "\u001b[01mcopying static files... ... \u001b[39;49;00mdone\n",
      "\u001b[01mcopying extra files... \u001b[39;49;00mdone\n",
      "\u001b[01mdumping search index in English (code: en)... \u001b[39;49;00mdone\n",
      "\u001b[01mdumping object inventory... \u001b[39;49;00mdone\n",
      "\u001b[01mbuild succeeded, 6 warnings.\u001b[39;49;00m\n",
      "\n",
      "The HTML pages are in build/html.\n"
     ]
    }
   ],
   "source": [
    "!make html O=-a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
